package mzt;

import java.nio.file.Paths;

import org.jsoup.Jsoup;
import org.jsoup.select.Elements;

public class Page {
	private String alt;
	private String href;
	private int num;

	public Page(String href) {
		System.out.println("down" + href);
		setHref(href);
		this.alt = getTitle(href);
		Paths.get(Constant.SAVE_FILE + href.substring(href.lastIndexOf("/" ))).toFile().mkdirs();
	}

	/**
	 * 图片标题
	 * 
	 * @param hef
	 * @return
	 */
	private String getTitle(String hef) {
		String connReturnBody = Utils.connReturnBody(hef);
		Elements pgeTitle = Jsoup.parse(connReturnBody).getElementsByClass(Constant.PAGE_TITLE_CLASS);
		return pgeTitle.text();
	}

	public String getAlt() {
		return alt;
	}

	public void setAlt(String alt) {
		this.alt = alt;
	}

	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.num = Utils.getNumByUrl(href, Constant.DETIAL_PAGE_NUM_CLASS);
		this.href = href;
	}

	public int getNum() {
		return num;
	}

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		String string = "http://www.mzitu.com/99717";
		String substring = string.substring(1);
		System.err.println(string.lastIndexOf("/"));
		System.out.println(string.substring(21));
	}
}
